<template>
  <el-dialog
    v-if="visible"
    v-model="visible"
    :draggable="draggable"
    :width="width"
    :fullscreen="fullscreen && isFullscreen"
    v-bind="$attrs"
    v-on="$attrs"
    :show-close="false"
    :before-close="handleClose"
    :close-on-click-modal="false"
  >
    <template #header>
      <div class="dialog-header">
        <div class="dialog-header__title">{{ title }}</div>
        <div class="dialog-header__right">
          <i v-if="fullscreen" class="font_family icon-quanping" @click="handleFullscreen"> </i>
          <i class="font_family icon-guanbidangqianbiaoqianye" @click="handleClose"> </i>
        </div>
      </div>
    </template>
    <slot></slot>
    <template #footer
      ><slot name="footer">
        <div v-if="showFotter" class="dialog-footer">
          <FIButton @click="handleClose">取消</FIButton>
          <FIButton :loading="confirmLoading" type="primary" @click="handleConfirm"> 确定 </FIButton>
        </div>
        <div v-else class="dialog-footer">
          <FIButton type="primary" @click="handleClose">关闭</FIButton>
        </div>
      </slot></template
    >
  </el-dialog>
</template>
<script setup lang="ts">
import FIButton from './FIButton.vue'
import { computed, ref } from 'vue'
const props = defineProps({
  title: {
    type: String,
    default: '',
  },
  width: {
    type: String,
    default: '1180px',
  },
  modelValue: {
    type: Boolean,
    default: false,
  },
  showFotter: {
    type: Boolean,
    default: true,
  },
  fullscreen: {
    type: Boolean,
    default: true,
  },
  draggable: {
    type: Boolean,
    default: true,
  },
  confirmLoading: {
    type: Boolean,
    default: false,
  },
})
const isFullscreen = ref(false)
const handleFullscreen = () => {
  isFullscreen.value = !isFullscreen.value
}
const emits = defineEmits(['update:modelValue', 'confirm', 'update:fullscreen'])
const handleClose = () => {
  emits('update:modelValue', false)
}
const handleConfirm = () => {
  emits('confirm')
}

let visible: any = computed({
  get() {
    return props.modelValue
  },
  set(val) {
    emits('update:modelValue', val)
  },
})
defineExpose({ handleClose })
</script>
<style lang="less" scoped>
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: -15px -20px 0 0;
  .dialog-header__title {
    font-size: 18px;
    color: #303133;
    line-height: 28px;
    font-weight: bold;
  }
  i {
    width: 20px;
    margin-left: 24px;
    &:hover {
      cursor: pointer;
      color: var(--el-color-primary);
    }
  }
}
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  margin: -15px -6px -10px 0;
}
</style>
